package com.laobindj.siji.adapter;

/*
 * 创业菜谱-分类(标签)
 */

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.List;

import com.laobindj.siji.R;
import com.laobindj.siji.listener.ItemClickListener;
import com.laobindj.siji.model.OtherExpensesBean;


/**
 * TODO<>
 *
 * @author wen_er
 * @data: 2015年6月5日 下午2:57:16
 * @version: V1.0
 */
public class RechargeMobileLableAdapter extends BaseAdapter {

    private Context context;
    private List<OtherExpensesBean.DataBean> listData;
    String rechargeType;

    private LayoutInflater layoutInflater;
    private ItemClickListener mItemClickListener;

    public int clickTemp = -1;

    public RechargeMobileLableAdapter(Context context, List<OtherExpensesBean.DataBean> mList,
                                      String rechargeType) {
        this.layoutInflater = LayoutInflater.from(context);
        this.context = context;
        this.rechargeType = rechargeType;
        this.listData = mList;
    }

    public void addAll(List<OtherExpensesBean.DataBean> info) {
        listData.clear();
        listData.addAll(info);
        notifyDataSetChanged();
    }

    public void setItemClickListener(ItemClickListener mItemClickListener) {

        this.mItemClickListener = mItemClickListener;
    }

    @Override
    public int getCount() {
        return listData != null ? listData.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return listData.get(position);
    }

    @Override
    public long getItemId(int arg0) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup arg2) {
        final ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = layoutInflater.inflate(R.layout.item_recharge_mobile_lable, null);

            holder.title = (TextView) convertView.findViewById(R.id.lable_nameTv);
            holder.real_money = (TextView) convertView.findViewById(R.id.lable_real_money_Tv);
            holder.recharge_mobile_ll = (LinearLayout) convertView.findViewById(R.id.recharge_mobile_ll);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.title.setText(listData.get(position).getName());

//        if ("话费".equals(rechargeType)) {
//            holder.real_money.setText("售价" + listData.get(position).getInprice());
//        } else {
//            holder.real_money.setText(listData.get(position).getInprice() + "元");
//        }

        if (clickTemp == position) {
            holder.recharge_mobile_ll.setBackground(context.getResources().getDrawable(R.drawable.shape_stroke_mainbg_solid_mainbg));
            holder.title.setTextColor(context.getResources().getColor(R.color.white));
            holder.real_money.setTextColor(context.getResources().getColor(R.color.white));

        } else {
            holder.recharge_mobile_ll.setBackground(context.getResources().getDrawable(R.drawable.shape_stroke_black_solid_empty));
            holder.title.setTextColor(context.getResources().getColor(R.color.text_font_black_light));
            holder.real_money.setTextColor(context.getResources().getColor(R.color.text_font_black_light));
        }
        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mItemClickListener != null) {
                    mItemClickListener.onItemClick(holder.title, position);
                }
            }
        });

        return convertView;
    }

    public void setSelection(int position) {
        clickTemp = position;
    }

    public class ViewHolder {
        public TextView title;
        public TextView real_money;
        public LinearLayout recharge_mobile_ll;


    }

}
